<template>
  <div>
    <el-dialog
      :close-on-click-modal="false"
      v-model="visibleDialog"
      :title="props.title"
      width="1100px"
      draggable
      destroy-on-close
      align-center
      @close="closeDialog"
      class="maxhDialog"
    >
      <!-- 查看模式 -->
      <div v-if="props.isReadonly" style="width: 99%">
        <h3 class="mb-[4px] mt-[0px] c-[#333] text-[15px] font-400 lh-[28px]">
          基本信息
        </h3>
        <el-descriptions
          title=""
          :column="3"
          size="large"
          border
          style="width: 100%"
        >
          <el-descriptions-item :span="1">
            <template #label>
              <div class="cell-item">器具</div>
            </template>
            <span>{{ formData?.assetName || "" }}</span>
          </el-descriptions-item>
          <el-descriptions-item :span="1">
            <template #label>
              <div class="cell-item">检定内容</div>
            </template>
            <span>{{ formData?.standardName || "" }}</span>
          </el-descriptions-item>
          <el-descriptions-item
            :span="1"
            v-show="formData?.usingDepartmentName"
          >
            <template #label>
              <div class="cell-item">使用部门</div>
            </template>
            <span>{{ formData?.usingDepartmentName || "" }}</span>
          </el-descriptions-item>
          <el-descriptions-item :span="1" v-if="formData?.usingPersonName">
            <template #label>
              <div class="cell-item">使用人</div>
            </template>
            <span>{{ formData?.usingPersonName || "" }}</span>
          </el-descriptions-item>
          <el-descriptions-item :span="1" v-if="formData?.measuringRange">
            <template #label>
              <div class="cell-item">测量范围</div>
            </template>
            <span>{{ formData?.measuringRange || "" }}</span>
          </el-descriptions-item>
          <el-descriptions-item :span="1" v-if="formData?.measuringDivision">
            <template #label>
              <div class="cell-item">分度</div>
            </template>
            <span>{{ formData?.measuringDivision || "" }}</span>
          </el-descriptions-item>
          <el-descriptions-item :span="1" v-if="formData?.makerName">
            <template #label>
              <div class="cell-item">制造商</div>
            </template>
            <span>{{ formData?.makerName || "" }}</span>
          </el-descriptions-item>
          <el-descriptions-item :span="1" v-if="formData?.manufactureCode">
            <template #label>
              <div class="cell-item">出厂编号</div>
            </template>
            <span>{{ formData?.manufactureCode || "" }}</span>
          </el-descriptions-item>
          <el-descriptions-item :span="1" v-if="formData?.checkPeriod">
            <template #label>
              <div class="cell-item">检定周期</div>
            </template>
            <span>{{ formData?.checkPeriod || "" }}</span>
          </el-descriptions-item>
        </el-descriptions>

        <h3
          v-if="formData.details && formData.details.length"
          class="mb-[4px] mt-[20px] c-[#333] text-[15px] font-400 lh-[28px]"
        >
          检定项目
        </h3>

        <div
          class="formTable1"
          v-if="formData.details && formData.details.length"
        >
          <el-table
            :data="formData.details"
            style="width: 100%"
            :key="Math.random"
            border
            :cell-style="{ 'text-align': 'center' }"
          >
            <el-table-column
              type="index"
              label="序号"
              align="center"
              width="100"
            />
            <el-table-column
              label="检定项目内容"
              prop="sopItemName"
              min-width="150"
            />
            <el-table-column label="检定值" prop="sopItemResult" width="200">
              <template #default="{ $index, row }">
                <span>{{ row.sopItemResult }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="检定项目标准"
              prop="sopItemStandardValue"
              min-width="150"
            />
          </el-table>
        </div>

        <h3 class="mb-[4px] mt-[20px] c-[#333] text-[15px] font-400 lh-[28px]">
          检定总结
        </h3>
        <el-descriptions
          title=""
          :column="3"
          size="large"
          border
          style="width: 100%"
        >
          <el-descriptions-item :span="1">
            <template #label>
              <div class="cell-item">校准结论</div>
            </template>
            <span>{{ formData?.calibrateResult || "" }}</span>
          </el-descriptions-item>
          <el-descriptions-item :span="1" v-if="formData?.calibrateTemp">
            <template #label>
              <div class="cell-item">校准温度</div>
            </template>
            <span v-if="formData?.calibrateTemp"
              >{{ formData?.calibrateTemp }}℃</span
            >
            <span v-else></span>
          </el-descriptions-item>
          <el-descriptions-item :span="1">
            <template #label>
              <div class="cell-item">检定员</div>
            </template>
            <span>{{ formData?.calibratePersonName || "" }}</span>
          </el-descriptions-item>
          <el-descriptions-item :span="1" v-if="formData?.calibratePlace">
            <template #label>
              <div class="cell-item">检定地点</div>
            </template>
            <span>{{ formData?.calibratePlace || "" }}</span>
          </el-descriptions-item>
          <el-descriptions-item :span="1">
            <template #label>
              <div class="cell-item">核验员</div>
            </template>
            <span>{{ formData?.verificationPersonName || "" }}</span>
          </el-descriptions-item>
          <el-descriptions-item :span="1">
            <template #label>
              <div class="cell-item">检定日期</div>
            </template>
            <span>{{
              dayjs(formData.calibrateDate).format("YYYY-MM-DD") || ""
            }}</span>
          </el-descriptions-item>
          <el-descriptions-item :span="1">
            <template #label>
              <div class="cell-item">有效日期</div>
            </template>
            <span>{{
              dayjs(formData.effectivedDate).format("YYYY-MM-DD") || ""
            }}</span>
          </el-descriptions-item>
        </el-descriptions>
      </div>

      <!-- 表单模式 -->
      <el-form
        ref="formRef"
        :model="formData"
        :inline="true"
        :rules="rules"
        label-width="100"
        v-if="!props.isReadonly"
        style="width: 98%"
      >
        <div class="flex justify-center w-full">
          <el-steps
            style="width: 900px; margin-bottom: 50px"
            :active="activeStep"
            align-center
            finish-status="success"
          >
            <el-step title="基本信息" description="器具和检定内容选择" />
            <el-step title="检定项目" description="检定项目明细值填写" />
            <el-step
              title="检定总结"
              description="总结、日期、人员及其他信息填写"
            />
          </el-steps>
        </div>

        <!-- 第一步 基础数据 -->
        <div
          v-show="activeStep === 0"
          class="flex justify-center items-start h-[180px]"
        >
          <el-row style="width: 95%">
            <el-col :span="8">
              <el-form-item label="器具" prop="assetId">
                <el-input
                  v-if="!props.isReadonly"
                  v-model="formData.assetName"
                  placeholder="请选择器具"
                  clearable
                  @focus="openSelectDialog()"
                />
                <span v-else>{{ formData.assetName }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="检定内容" prop="standardId">
                <el-select
                  v-model="formData.standardId"
                  placeholder="请选择检定内容"
                  clearable
                  v-if="!props.isReadonly"
                  @change="changeStandardId"
                  style="width: 100%"
                >
                  <el-option
                    v-for="item in standardIdList"
                    :key="`${item.id}`"
                    :label="`${item.standardName}`"
                    :value="`${item.id}`"
                  />
                </el-select>
                <span v-else>{{ formData?.standardName || "" }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="使用部门">
                <el-input
                  v-if="!props.isReadonly"
                  v-model="formData.usingDepartmentName"
                  placeholder=""
                  clearable
                  disabled
                />
                <span v-else>{{ formData.usingDepartmentName }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="使用人">
                <el-input
                  v-if="!props.isReadonly"
                  v-model="formData.usingPersonName"
                  placeholder=""
                  clearable
                  disabled
                />
                <span v-else>{{ formData.usingPersonName }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="测量范围">
                <el-input
                  v-if="!props.isReadonly"
                  v-model="formData.measuringRange"
                  placeholder=""
                  clearable
                  disabled
                />
                <span v-else>{{ formData.measuringRange }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="分度">
                <el-input
                  v-if="!props.isReadonly"
                  v-model="formData.measuringDivision"
                  placeholder=""
                  clearable
                  disabled
                />
                <span v-else>{{ formData.measuringDivision }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="制造商">
                <el-input
                  v-if="!props.isReadonly"
                  v-model="formData.makerName"
                  placeholder=""
                  clearable
                  disabled
                />
                <span v-else>{{ formData.makerName }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="出厂编号">
                <el-input
                  v-if="!props.isReadonly"
                  v-model="formData.manufactureCode"
                  placeholder=""
                  clearable
                  disabled
                />
                <span v-else>{{ formData.manufactureCode }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="检定周期">
                <el-input
                  v-if="!props.isReadonly"
                  v-model="formData.checkPeriod"
                  placeholder=""
                  clearable
                  disabled
                />
                <span v-else>{{ formData.checkPeriod }}</span>
              </el-form-item>
            </el-col>
          </el-row>
        </div>

        <!-- 第二布 检定明细 -->
        <div
          v-show="activeStep === 1"
          class="flex justify-center items-start"
          style="min-height: 180px"
        >
          <el-row style="width: 95%">
            <el-col :span="24">
              <div class="formTable1">
                <el-table
                  :data="formData.details"
                  style="width: 100%"
                  :key="Math.random"
                  border
                  :cell-style="{ 'text-align': 'center' }"
                >
                  <el-table-column
                    type="index"
                    label="序号"
                    align="center"
                    width="100"
                  />
                  <el-table-column
                    label="检定项目内容"
                    prop="sopItemName"
                    min-width="150"
                  />
                  <!-- <el-table-column
                    label="检定项目类型"
                    prop="standardValue"
                    min-width="60"
                  >
                    <template #default="{ $index, row }">
                      <el-tag v-if="row.standardValue == 1">测量</el-tag>
                      <el-tag v-if="row.standardValue == 2" type="warning"
                        >非测量</el-tag
                      >
                    </template>
                  </el-table-column> -->
                  <el-table-column
                    label="检定值"
                    prop="sopItemResult"
                    width="200"
                  >
                    <template #default="{ $index, row }">
                      <!-- <div v-if="row.standardValue == 1" class="flex">
                        <el-form-item
                          :prop="'details.' + $index + '.standardMinValue'"
                          labelWidth="0"
                          class="flex-1"
                        >
                          <el-input
                            v-if="!props.isReadonly"
                            v-model="row.standardMinValue"
                            placeholder="最小值"
                            clearable
                          />
                          <span v-else>{{ row.standardMinValue }}</span>
                        </el-form-item>
                        <div class="standard-range">~</div>
                        <el-form-item
                          :prop="'details.' + $index + '.standardMaxValue'"
                          labelWidth="0"
                          class="flex-1"
                        >
                          <el-input
                            v-if="!props.isReadonly"
                            v-model="row.standardMaxValue"
                            placeholder="最大值"
                            clearable
                          />
                          <span v-else>{{ row.standardMaxValue }}</span>
                        </el-form-item>
                      </div>
                      <div v-if="row.standardValue == 2">
                        <el-form-item
                          :prop="'details.' + $index + '.resultValue'"
                          label-width="0"
                        >
                          <el-select
                            v-model="row.resultValue"
                            placeholder="请选择"
                            clearable
                          >
                            <el-option label="正常" value="1" />
                            <el-option label="异常" value="0" />
                          </el-select>
                        </el-form-item>
                      </div> -->
                      <el-form-item
                        :prop="'details.' + $index + '.sopItemResult'"
                        :rules="rules.sopItemResult"
                        label-width="0"
                      >
                        <el-input
                          v-if="!props.isReadonly"
                          v-model="row.sopItemResult"
                          placeholder="请输入检定值"
                          clearable
                        />
                        <span v-else>{{ row.sopItemResult }}</span>
                      </el-form-item>
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="检定项目标准"
                    prop="sopItemStandardValue"
                    min-width="150"
                  />
                </el-table>
              </div>
            </el-col>
          </el-row>
        </div>

        <!-- 第三步 检定结论 -->
        <div
          v-show="activeStep === 2"
          class="flex justify-center items-start h-[180px]"
        >
          <el-row style="width: 95%">
            <el-col :span="8">
              <el-form-item label="校准结论" prop="calibrateResult">
                <el-input
                  v-if="!props.isReadonly"
                  v-model="formData.calibrateResult"
                  placeholder="请输入校准结论"
                  clearable
                />
                <span v-else>{{ formData.calibrateResult }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="校准温度" prop="calibrateTemp">
                <el-input
                  v-if="!props.isReadonly"
                  v-model="formData.calibrateTemp"
                  placeholder="请输入校准温度"
                  clearable
                >
                  <template #append>℃</template>
                </el-input>
                <span v-else>{{ formData.calibrateTemp }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="检定员" prop="calibratePersonName">
                <el-input
                  v-if="!props.isReadonly"
                  v-model="formData.calibratePersonName"
                  placeholder="请输入检定员"
                  clearable
                />
                <span v-else>{{ formData.calibratePersonName }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="检定地点" prop="calibratePlace">
                <el-input
                  v-if="!props.isReadonly"
                  v-model="formData.calibratePlace"
                  placeholder="请输入检定地点"
                  clearable
                />
                <span v-else>{{ formData.calibratePlace }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="核验员" prop="verificationPersonName">
                <el-input
                  v-if="!props.isReadonly"
                  v-model="formData.verificationPersonName"
                  placeholder="请输入核验员"
                  clearable
                />
                <span v-else>{{ formData.verificationPersonName }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="检定日期" prop="calibrateDate">
                <el-date-picker
                  v-if="!props.isReadonly"
                  v-model="formData.calibrateDate"
                  value-format="YYYY-MM-DD"
                  format="YYYY-MM-DD"
                  clearable
                  type="date"
                  placeholder="请选择检定日期"
                  style="width: 100%"
                />
                <span v-else>{{ formData.calibrateDate }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="有效日期" prop="effectivedDate">
                <el-date-picker
                  v-if="!props.isReadonly"
                  v-model="formData.effectivedDate"
                  value-format="YYYY-MM-DD"
                  format="YYYY-MM-DD"
                  clearable
                  type="date"
                  placeholder="请选择有效日期"
                  style="width: 100%"
                />
                <span v-else>{{ formData.effectivedDate }}</span>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>

      <template #footer>
        <div class="dialog-footer">
          <el-button
            v-if="!props.isReadonly && activeStep !== 0"
            type="primary"
            plain
            @click="changeActiveStep(0)"
            >上一步</el-button
          >
          <el-button
            v-if="!props.isReadonly && activeStep !== 2"
            type="primary"
            plain
            @click="changeActiveStep(1)"
            >下一步</el-button
          >
          <el-button @click="closeDialog">取 消</el-button>
          <el-button
            v-if="!props.isReadonly && activeStep === 2"
            type="primary"
            :loading="loading"
            @click="handleSubmit"
            >提 交</el-button
          >
        </div>
      </template>
    </el-dialog>
    <eamChangeStatus-select
      :visible="selectDialog.visible"
      @change-visible="changeVisible"
    />
  </div>
</template>

<script setup lang="ts">
import request from "@/utils/request";
import dayjs from "dayjs";
import { validateIsNumber } from "@/utils/commonHooks";

defineOptions({
  name: "EAMEAMMTCALIBRATEORDERADDORUPDATE",
  inheritAttrs: false,
});

const emit = defineEmits(["reset-table", "change-visible"]);

const props = defineProps({
  visible: {
    type: Boolean,
    default: () => {
      return false;
    },
  },
  title: {
    type: String,
    default: () => {
      return "";
    },
  },
  data: {
    type: Object,
    default: () => {
      return {};
    },
  },
  isReadonly: {
    type: Boolean,
    default: () => {
      return false;
    },
  },
});

/** 弹窗显示 **/
const visibleDialog = ref(false);
watch(
  () => props.visible,
  (newVal: boolean) => {
    visibleDialog.value = newVal;
    setTimeout(() => {
      if (formRef.value && formRef.value?.clearValidate) {
        formRef.value.clearValidate();
      }
    }, 50);
  }
);

/** formData定义表单数据 */
const formRef = ref(ElForm);
let formData = reactive({
  id: "",
  version: "",
  orderNo: "",
  assetId: "",
  assetCode: "",
  assetName: "",
  assetTypeId: "",
  assetTypeName: "",
  standardId: "",
  standardName: "",
  usingDepartmentId: "",
  usingDepartmentName: "",
  usingPersonId: "",
  usingPersonName: "",
  calibrateResult: "",
  calibrateDate: "",
  effectivedDate: "",
  calibrateTemp: "",
  calibratePlace: "",
  calibratePersonName: "",
  verificationPersonName: "",
  remarks: "",
  createTime: "",
  createdUserId: "",
  createdUserName: "",
  lastUpdateTime: "",
  lastUpdatedUserId: "",
  lastUpdatedUserName: "",
  details: [],

  measuringRange: "",
  measuringDivision: "",
  makerName: "",
  makerId: "",
  manufactureCode: "",
  checkPeriod: "",
});

function validateEndTime(rule, value, callback) {
  if (formData.calibrateDate && value < formData.calibrateDate) {
    callback(new Error("有效日期不能小于检定日期"));
  } else {
    callback();
  }
}

/** rules规则 */
const rules = reactive({
  assetId: [
    { required: true, message: "请选择器具", trigger: "blur" },
    { min: 1, max: 32, message: "长度在 1 到 32 个字符", trigger: "blur" },
  ],
  standardId: [
    { required: true, message: "请选择检定内容", trigger: "change" },
  ],
  calibrateResult: [
    { required: true, message: "请输入校准结论", trigger: "blur" },
    { min: 1, max: 32, message: "长度在 1 到 32 个字符", trigger: "blur" },
  ],
  calibrateDate: [
    { required: true, message: "请选择检定日期", trigger: "change" },
  ],
  effectivedDate: [
    { required: true, message: "请选择有效日期", trigger: "change" },
    { validator: validateEndTime, trigger: "change" },
  ],
  calibrateTemp: [
    { min: 1, max: 32, message: "长度在 1 到 32 个字符", trigger: "blur" },
    { validator: validateIsNumber, trigger: "blur" },
  ],
  calibratePlace: [
    { min: 1, max: 50, message: "长度在 1 到 50 个字符", trigger: "blur" },
  ],
  calibratePersonName: [
    { required: true, message: "请输入检定员", trigger: "blur" },
    { min: 1, max: 50, message: "长度在 1 到 50 个字符", trigger: "blur" },
  ],
  verificationPersonName: [
    { required: true, message: "请输入核验员", trigger: "blur" },
    { min: 1, max: 50, message: "长度在 1 到 50 个字符", trigger: "blur" },
  ],
  remarks: [
    { min: 1, max: 255, message: "长度在 1 到 255 个字符", trigger: "blur" },
  ],
  sopItemResult: [
    { required: false, message: "请输入检定值", trigger: "blur" },
    { min: 1, max: 50, message: "长度在 1 到 50 个字符", trigger: "blur" },
  ],
});

const isValidated = ref(false);

/** 编辑时赋值 */
watch(
  () => props.data,
  (newVal: any) => {
    formData.id = "";
    if (newVal?.id) {
      Object.assign(formData, props.data);
      formData.details = props.data.details || [];
      if (formData.id) {
        if (!props.isReadonly) {
          getStandardList(props.data.assetTypeId);
        }
      }
    }
  }
);

/** 关闭表单弹窗 */
function closeDialog() {
  visibleDialog.value = false;
  emit("change-visible", false);
  resetForm();
}

/** 重置表单 */
function resetForm() {
  if (formRef.value && formRef.value?.resetFields) {
    formRef.value.resetFields();
    formRef.value.clearValidate();
  }

  activeStep.value = 0;
  formData.details = [];
  formData.id = "";
  formData.version = "";
  formData.orderNo = "";
  formData.assetId = "";
  formData.assetCode = "";
  formData.assetName = "";
  formData.assetTypeId = "";
  formData.assetTypeName = "";
  formData.standardId = "";
  formData.standardName = "";
  formData.usingDepartmentId = "";
  formData.usingDepartmentName = "";
  formData.usingPersonId = "";
  formData.usingPersonName = "";
  formData.calibrateResult = "";
  formData.calibrateDate = "";
  formData.effectivedDate = "";
  formData.calibrateTemp = "";
  formData.calibratePlace = "";
  formData.calibratePersonName = "";
  formData.verificationPersonName = "";
  formData.remarks = "";
  formData.createTime = "";
  formData.createdUserId = "";
  formData.createdUserName = "";
  formData.lastUpdateTime = "";
  formData.lastUpdatedUserId = "";
  formData.lastUpdatedUserName = "";

  formData.measuringRange = "";
  formData.measuringDivision = "";
  formData.makerName = "";
  formData.makerId = "";
  formData.manufactureCode = "";
  formData.checkPeriod = "";
}

const loading = ref(false);

/** 器具检定工单保存提交 */
function handleSubmit() {
  formRef.value.validate(async (valid: any) => {
    if (valid) {
      loading.value = true;
      const text = formData.id ? "编辑" : "新增";
      console.log("formData", toRaw(formData));
      await request({
        url: "/eam/eammtcalibrateorder/save",
        method: "post",
        data: formData,
      }).finally(() => {
        loading.value = false;
      });
      ElMessage.success(text + `成功`);
      closeDialog();
      emit("reset-table", formData.id);
      isValidated.value = false;
    } else {
      isValidated.value = true;
    }
  });
}

// async function getdetails() {
//   let sondetails = await request({
//     url: "/eam/eammtcalibrateorder/getDetails",
//     method: "post",
//     data: formData,
//   }).finally(() => {
//     loading.value = false;
//   });
//   formData.details = sondetails.data;
// }

const activeStep = ref(0);

function changeActiveStep(type: number) {
  if (type === 0) {
    // 0 上一步
    activeStep.value = activeStep.value - 1;
  } else if (type === 1) {
    if (activeStep.value === 0) {
      formRef.value
        .validateField(["assetId", "standardId"])
        .then(() => {
          activeStep.value = activeStep.value + 1;
        })
        .catch((err: any) => {});
    } else if (activeStep.value === 1) {
      if (!formData.details || formData.details.length === 0) {
        ElMessage.error("作业项不能为空，请先给检定内容添加作业项");
        return;
      }
      let ruleArr: string[] = [];
      formData.details?.map((item, index) => {
        ruleArr.push(`details.${index}.sopItemResult`);
      });
      if (ruleArr.length) {
        formRef.value
          .validateField(ruleArr)
          .then(() => {
            activeStep.value = activeStep.value + 1;
          })
          .catch((err: any) => {});
      } else {
        activeStep.value = activeStep.value + 1;
      }
    }
  }
}

//器具显隐
const selectDialog = ref({
  visible: false,
});
function openSelectDialog() {
  breakList.value = [];
  selectDialog.value.visible = true;
}
const breakList = ref([]);
const changeVisible = (val: boolean, data: any) => {
  if (data) {
    if (formData.assetId !== data.id) {
      standardIdList.value = [];
      formData.details = [];
      getStandardList(data.assetTypeId);
    }
    setOtherInfo(data);
  }
  selectDialog.value.visible = val;
};

function setOtherInfo(data: any) {
  formData.assetTypeName = data?.assetTypeName || "";
  formData.assetTypeId = data?.assetTypeId || "";
  formData.assetCode = data?.assetCode || "";
  formData.assetId = data?.id || "";
  formData.assetName = data?.assetName || "";

  formData.usingDepartmentId = data?.usingDepartmentId || "";
  formData.usingDepartmentName = data?.usingDepartmentName || "";
  formData.usingPersonId = data?.usingPersonId || "";
  formData.usingPersonName = data?.usingPersonName || "";

  formData.measuringRange = data?.measuringRange || "";
  formData.measuringDivision = data?.measuringDivision || "";
  formData.makerName = data?.makerName || "";
  formData.makerId = data?.makerId || "";
  formData.manufactureCode = data?.manufactureCode || "";
  formData.checkPeriod = data?.checkPeriod || "";
}

// 获取检定内容列表信息
const standardIdList: any = ref();
async function getStandardList(id: string) {
  const { data } = await request({
    url: "/eam/eammtcalibrateorder/getStandardList",
    method: "post",
    data: {
      equipTypeId: id,
    },
  });
  standardIdList.value = data || [];
}

// 检定问题改变处理
function changeStandardId(id: string) {
  if (id) {
    formData.standardName =
      standardIdList.value?.filter((e) => e.id === id)[0]?.standardName || "";
    getDetailTable();
  } else {
    formData.standardName = "";
    formData.details = [];
  }
}

// 获取检定内容详情
async function getDetailTable() {
  const { data } = await request({
    url: "/eam/eammtcalibrateorder/getStandardItemList/" + formData.standardId,
    method: "get",
    data: {},
  });
  formData.details = data || [];
}
</script>

<style lang="scss" scoped>
h4 {
  font-weight: 400;
  color: #000;
  padding-left: 10px;
  font-size: 14px;
  line-height: 14px;
}
.formTable1 {
  :deep(.el-form-item) {
    margin: 0 0 13px 0 !important;
    width: 100%;
  }
  :deep(.el-table__body td.el-table__cell) {
    padding: 0 !important;
  }
}

:deep(.el-dialog .formTable1 .el-table .el-form-item) {
  padding: 11px 0 0 0 !important;
}
:deep(.el-dialog .formTable1 .el-table .el-form-item__error) {
  font-size: 11px !important;
}

:deep(.maxhDialog .el-dialog__body) {
  max-height: 70vh;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  justify-content: center;
  .el-form-item {
    width: 100%;
  }
}
:deep(.search-container .el-input.el-input--default.el-input--suffix) {
  // 固定宽度
  width: 190px !important;
}
:deep(.search-container .el-form-item--default .el-form-item__label) {
  // 固定宽度
  justify-content: end;
}
:deep(.el-descriptions__label.el-descriptions__cell.is-bordered-label) {
  width: 120px;
}
:deep(.el-descriptions__content.el-descriptions__cell.is-bordered-content) {
  min-width: 180px;
  word-break: break-all;
}
.standard-range {
  line-height: 33px;
  padding: 0 5px;
  align-items: center;
  display: flex;
}
</style>
